package com.bmsbosmpa.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bmsbosmpa.entity.Book;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class BookDaoTestCase {

    @Autowired
    private IBookDao bookDao;

    // 查全部
    @Test
    public void testSelectAll() {
        bookDao.selectList(null);
    }

    // 分页
    @Test
    public void testGetPage(){
        IPage iPage = new Page(2, 5);// 页码， 页码内容条数
        bookDao.selectPage(iPage, null);
        System.out.println(iPage.getCurrent());
        System.out.println(iPage.getSize());
        System.out.println(iPage.getTotal());
        System.out.println(iPage.getPages());
        System.out.println(iPage.getRecords());
    }

    // 条件查询
    @Test
    public void testSpecificSelect() {
        String name = "的";
        LambdaQueryWrapper<Book> queryWrapper = new LambdaQueryWrapper<>();
        // 非空判断
        queryWrapper.like(name != null, Book::getName, "的");
        bookDao.selectList(queryWrapper);
    }
}
